unit Con_VariacaoFicha;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Db, Dbtables,
  Grids, DBGrids;

type
  TFrmCon_VariacaoFicha = class(TFrmConsulta)
    DbgVariacao: TDBGrid;
    Label1: TLabel;
    EdtDescricao: TEdit;
    procedure BtnFecharClick(Sender: TObject);
    procedure EdtDescricaoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    Var_codigo : String;
    Pro_codigo : String;
  end;

var
  FrmCon_VariacaoFicha: TFrmCon_VariacaoFicha;

implementation

Uses Dm, Biblio, clsVariacao, clsFicha;

{$R *.DFM}

var Variacao : TVariacao;
    Ficha    : TFicha;
    tds      : Tdatasource;
    tq       : Tquery;

procedure TFrmCon_VariacaoFicha.BtnFecharClick(Sender: TObject);
begin
  inherited;
  Var_codigo:=tq.fieldbyname('Var_codigo').asstring;
  tds.free;
  tq.free;
end;

procedure TFrmCon_VariacaoFicha.EdtDescricaoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key=12 then begin
    FazConsulta;
    EdtDescricao.setfocus;
  end;
end;

procedure TFrmCon_VariacaoFicha.FormActivate(Sender: TObject);
begin
  inherited;
  tds:=TDataSource.create(FrmCon_VariacaoFicha);
  tq:=Tquery.create(FrmCon_VariacaoFicha);
  tq.databasename:=dmint.db.databasename;
  tq.active:=False;
  tds.DataSet:=tq;
  fazconsulta;
  EdtDescricao.setfocus;
end;

procedure TFrmCon_VariacaoFicha.FazConsulta;
begin
  if EdtDescricao.text='' then
    EdtDescricao.text := ' ';
  Ficha:=TFicha.Create;
  Ficha.Consultar_Variacao(tq,EdtDescricao.text, Pro_codigo);
  tq.open;
  Ficha.free;
  dbgVariacao.DataSource := tds;
  dbgVariacao.Refresh;
end;

end.
